package com.zj.ssm.controller;

import com.alibaba.excel.EasyExcel;
import com.zj.ssm.pojo.domain.PatResultQuery;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lilinhui
 * @author diao 2022/2/23 星期三 19:17
 */
@Controller
@RequestMapping("parsource")
public class ParSourceController {

    @RequestMapping("download")
    public void download(PatResultQuery query, HttpServletResponse response) throws Exception{

        List<PatResultQuery> patResultQueries = new ArrayList<PatResultQuery>();
        patResultQueries.add(query);
        System.out.println(patResultQueries);


        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");

        // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
        String fileName = URLEncoder.encode("患者信息", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");


        EasyExcel.write(   response.getOutputStream()  , PatResultQuery.class    )     .sheet("患者信息").doWrite(  patResultQueries  );

    }

}
